Skip to content

fix(controlplane): stop exposing pprof /debug endpoints on public listeners#3241

Merged
matiasinsaurralde merged 1 commit into
chainloop-dev:mainfrom
jiparis:fix/pprof-public-exposure
Jun 25, 2026
Merged

fix(controlplane): stop exposing pprof /debug endpoints on public listeners#3241
matiasinsaurralde merged 1 commit into
chainloop-dev:mainfrom
jiparis:fix/pprof-public-exposure

Conversation

@jiparis

@jiparis jiparis commented Jun 25, 2026

Copy link
Copy Markdown
Member

Summary

The controlplane exposed Go pprof /debug/pprof/* endpoints, unauthenticated, on the public API and metrics HTTP listeners regardless of the enable_profiler setting.

The cause is a combination of two behaviors:

  • The net/http/pprof blank import registers its handlers on the process-wide http.DefaultServeMux at init time.
  • go-kratos sets every HTTP server's NotFoundHandler (and MethodNotAllowedHandler) to http.DefaultServeMux, so any unmatched route falls through to those pprof handlers. The kratos auth/RBAC middleware does not run on that fall-through path.

As a result /debug/pprof/* was reachable on the public API port and the metrics port even with enable_profiler: false.

Changes

  • Add hardenedRouteOptions() which overrides NotFoundHandler/MethodNotAllowedHandler with plain 404/405 responses so no kratos HTTP server falls through to http.DefaultServeMux. Applied to the main API server, the metrics server, and the profiler server.
  • Register the pprof handlers explicitly on the opt-in profiler server's own router (private mux) instead of relying on the default-mux fall-through.
  • Remove the net/http/pprof blank imports from the controlplane entrypoint.

With these changes pprof is unreachable when profiling is disabled, and when enabled it is served only on the dedicated profiler port.

AI assistance

This change was produced with assistance from Claude Code.

Review in cubic

…teners

The net/http/pprof blank import registered its /debug/pprof/* handlers on
the process-wide http.DefaultServeMux, and go-kratos points every HTTP
server's NotFoundHandler at that mux. As a result the pprof endpoints were
reachable, unauthenticated, on the public API and metrics listeners
regardless of the enable_profiler setting.

Override NotFoundHandler/MethodNotAllowedHandler on every kratos HTTP server
so unmatched routes no longer fall through to DefaultServeMux, and register
the pprof handlers explicitly on the opt-in profiler server only.

Assisted-by: Claude Code
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>

Chainloop-Trace-Sessions: e6906bba-e9a1-468f-8d04-e3fe7ae231df

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/controlplane/internal/server/profiler.go
@matiasinsaurralde matiasinsaurralde merged commit 8efb6e0 into chainloop-dev:main Jun 25, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants